package com.yswy.common.utils;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class TgKlUtil {


    public static List<Integer> getList(Integer num) {
        List<Integer> integers = new ArrayList<>();
        if (num >= 100){
            for (int i = 0; i < 100; i++) {
                integers.add(0);
            }
            return  integers ;
        }else if (num <= 0){
            for (int i = 0; i < 100; i++) {
                integers.add(1);
            }
            return  integers ;
        }
        Integer a = num; //0
        Integer b = 100 - a; //1
        Integer min = Math.min(a, b);
        Integer max = Math.max(a, b);
        if (a > 50){
            integers = base(min, max , 0 , 1) ;
        }else {
            integers = base(min, max , 1 , 0) ;
        }

        if (integers != null){
            return integers ;
        }
        if (a > 50){
            integers = countLT25(min, max , 0 , 1 , 0);
        }else {
            integers = countLT25(min, max , 1 , 0 , 1);
        }
        return integers;
    }
    public static void main(String[] args) {
        List<Integer> integers = getList(0);
        System.out.println(integers.toString());
    }

    private static List<Integer> countLT25(Integer min, Integer max , int num1 , int  num2 , int num3) {
        boolean judge = max > min;
        Integer newMin = Math.min(min, max);
        Integer clm = judge ? (max / min) +1 : (min / max) +1;
        String lcmNumber = generateLcmNumber(clm -1 , num1 , num2);
        String s = generateLcmFrequencyNumbermax(lcmNumber, newMin ,max % min , num3 );
        String[] items = s.split(",");
        List<Integer> integers = Stream.of(items).map(Integer::parseInt).collect(Collectors.toList());
//        pringInt(  integers);
        return integers;
    }
    private static List<Integer> base(Integer min, Integer max ,  int num1 , int  num2 ) {
        if (0 != max % min) {
            return null;
        }
        // 最小倍数
        int lcm = max / min +1;
        // 倍数次数
        int lcmFrequency = (max + min) / lcm ;
        String lcmNumber = generateLcmNumber(lcm-1 , num1  , num2 );
        String s = generateLcmFrequencyNumber(lcmNumber, lcmFrequency);
        String[] items = s.split(",");
        List<Integer> integers = Stream.of(items).map(Integer::parseInt).collect(Collectors.toList());
//        pringInt(integers);
        return integers;
    }
    private static void pringInt( List<Integer> integers) {
        Iterator iterator=integers.iterator();
        int cc = 0 ;
        int bb = 0 ;
        while (iterator.hasNext()){
            Object key=iterator.next();
            System.out.print(key+" ");
            if (key.toString().equals("1")){
                cc ++ ;
            }else {
                bb ++ ;
            }

        }
        System.out.println();
        System.out.println( "-----------1的个数 " + cc + "    0 的个数 " + bb);
        System.out.println(integers.size());
    }

    private static String generateLcmNumber(int size , int num1 , int  num2) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < size; i++) {
            sb.append(num1);
        }
        sb.append(num2);
        return sb.toString();
    }
    private static String generateLcmFrequencyNumber(String lcmNumber, Integer lcmFrequency ) {
        StringBuilder sb = new StringBuilder();
        for (Integer i = 0; i < lcmFrequency; i++) {
            sb.append(lcmNumber);
        }
        String s = sb.toString();
        String returnstr = "" ;
        char[] chars = s.toCharArray();
        for (char c :chars
        ) {
            returnstr  += c +",";
        }
        return returnstr;
    }


    private static String generateLcmFrequencyNumbermax(String lcmNumber, Integer lcmFrequency , Integer max , int num) {
        StringBuilder sb = new StringBuilder();
        for (Integer i = 0; i < lcmFrequency; i++) {
            sb.append(lcmNumber);
        }

        Integer cuNum = sb.length() /max ;
        for (Integer i = 0; i < max; i++) {
            sb.insert(cuNum*i ,num );
        }

        String s = sb.toString();
        String returnstr = "" ;
        char[] chars = s.toCharArray();
        for (char c :chars
             ) {
            returnstr  += c +",";
        }
        return returnstr;
    }


}
